package com.kxxnzstdsw.config

import com.charleskorn.kaml.Yaml
import kotlinx.serialization.Serializable

@Serializable
data class Config(
  val env: ENV,
  val hikari: HikariConfig,
  val redis: RedisConfig,
  val jwt: JwtConfig,
  val quartz: QuartzConfig,
  val init: InitConfig,
  val versions: List<Version>
)

@Serializable
data class Version(
  val version: String,
  val log: String
)

@Serializable
data class HikariConfig(
  val username: String,
  val password: String,
  val jdbcUrl: String,
  val driverClassName: String,
  val isAutoCommit: Boolean = false,
  val transactionIsolation: String = "TRANSACTION_REPEATABLE_READ"
)

@Serializable
data class JwtConfig(
  val privateKey: String,
  val issuer: String,
  val audience: String,
  val realm: String,
  val kid: String
)

@Serializable
data class RedisConfig(
  val password: String,
  val host: String,
  val port: Int
)

@Serializable
data class QuartzConfig(
  val scanPath: String,
  val schedulerInstanceName: String,
  val schedulerInstanceId: String,
  val threadPoolClass: String,
  val threadPoolThreadCount: Int,
  val jobStoreClass: String,
  val jobStoreDriverDelegateClass: String,
)

fun Config(ymlStr: String): Config {
  return Yaml.default.decodeFromString(Config.serializer(), ymlStr)
}



